USE [BMIG_Mensual_POST_CADENA]
GO

/****** Object:  StoredProcedure [dbo].[WASP_M0003_REFUNDIMIENTO]    Script Date: 11/28/2011 12:11:10 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[WASP_M0003_REFUNDIMIENTO]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[WASP_M0003_REFUNDIMIENTO]
GO

USE [BMIG_Mensual_POST_CADENA]
GO

/****** Object:  StoredProcedure [dbo].[WASP_M0003_REFUNDIMIENTO]    Script Date: 11/28/2011 12:11:10 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[WASP_M0003_REFUNDIMIENTO]
AS

BEGIN
	SELECT
			aocta      = fsh016.hcta
			,Z07391Op1 = fsh016.hoper 
			,Z07391su1 = fsh016.hsucur
			,Z07394IMP = fsh016.hcimp1

	INTO dbo.montos_refundidos

	FROM  fsh016,
		  fsh015 

	WHERE
			fsh016.hfcon = fsh015.hfcon and
			fsh016.hcmod = fsh015.hcmod and
			fsh016.htran = fsh015.htran and
			fsh016.hnrel = fsh015.hnrel and
			fsh016.hsucor = fsh015.hsucor and
			fsh016.hcmod in (30, 32) and
		--fsh015.htran in (10,25) and
			fsh016.hrubro = 1111003210 and
			fsh015.hccorr <> 99 and 
			fsh016.hcodmo = 2 and
			fsh016.hsubop <= 99
END		

GO

